/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-19     desktop       the first version
 */
#include <all_code.h>

/*  导入log工具 */
#define DBG_TAG "palm.c"
#define DBG_LVL DBG_LOG
#include <rtdbg.h>

/*
 * 这里是个继电器，只需要调度它打开关闭，使用一个信号量和一个线程即可
 * */

/*  手心线程控制块 */
static rt_thread_t palm_scheduling_tid = RT_NULL;

/* 手心调度信号量 */
struct rt_semaphore palm_sch_semaphore;


static void palm_scheduling_entry(void *param)
{
    while(1)
    {
        //说明有数据变化，来查看一次数据调度
        rt_sem_take(&palm_sch_semaphore, RT_WAITING_FOREVER);

        if( temp_data[3] == 1)
        {
            rt_pin_write(Relay_PIN, PIN_LOW);
        }

        else if(temp_data[3] == 0)
        {
            rt_pin_write(Relay_PIN, PIN_HIGH);
        }
    }
}

void palm_app_creative(void)
{
    //初始化信号量
    rt_sem_init(&palm_sch_semaphore, "palm_sch_semaphore", 0, RT_IPC_FLAG_PRIO);

    //创建脚部调度线程并启动
    palm_scheduling_tid = rt_thread_create("palm_sch", palm_scheduling_entry, RT_NULL, 512, 14, 10);
    if(palm_scheduling_tid != RT_NULL)
    {
        rt_thread_startup(palm_scheduling_tid);
    }
}

